import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQml.Models 2.15


Popup {
    id: cusPromptPopupRoot
    implicitWidth: promptText.width + 20
    implicitHeight: promptText.height + 17
    closePolicy: Popup.CloseOnEscape
    visible: false

    x: -(width - parent.width) / 2
    y: parent.height + 5

    property alias text: promptText.text
    property int interval: 500
    readonly property color back_color: "#C8171717"

    function close(){
        showTimer.stop()
        cusPromptPopupRoot.visible = false
    }

    function show(){
        showTimer.start()
    }

    Timer{
        id: showTimer
        interval: cusPromptPopupRoot.interval
        repeat: false
        running: false
        onTriggered: {
            cusPromptPopupRoot.visible = true
        }
    }

    background: Rectangle{
        color: "transparent"

        Rectangle {
            id: arrow
            anchors.top: parent.top
            anchors.horizontalCenter: parent.horizontalCenter
            implicitWidth: 10
            implicitHeight: 5
            color: "transparent"

            Canvas {
                id: arrowCanvas
                anchors.fill: parent

                onPaint: {
                    var ctx = getContext("2d");
                    ctx.fillStyle = back_color
                    ctx.strokeStyle = "transparent"
                    ctx.lineWidth = 1

                    ctx.beginPath()
                    ctx.moveTo(0, parent.height)
                    ctx.lineTo(parent.width / 2, 0)
                    ctx.lineTo(parent.width, parent.height)
                    ctx.stroke()
                    ctx.fill()
                }
            }
        }

        Rectangle {
            anchors.top: arrow.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            color: back_color
            radius: 4

            CusText {
                id: promptText
                text: "Non"
                color: "white"

                font.pixelSize: Theme.font_size_13
                font.styleName: Theme.font_family_regular
                anchors.centerIn: parent
            }
        }
    }
}
